package CodingTest;

import javax.swing.tree.TreeNode;
import java.util.*;

public class BinTreeDFS {
    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }}
    public List<TreeNode> Dfs_tree(TreeNode root){
        Stack<TreeNode> sta = new Stack<>();
        List<TreeNode> res = new ArrayList<>();
        if(root == null) return null;
        //res.add(root);
        sta.add(root);
        while(!sta.isEmpty()){
            TreeNode temp = sta.pop();
            res.add(temp);
            if(temp.right != null) sta.push(temp.right);
            if(temp.left != null) sta.push(temp.left);
        }
        return res;
    }
}
